package framework.netty;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.minidev.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;


/**
 * controller
 *
 * @author ME
 */
@Controller
@RequestMapping(value = "/user", produces = "text/json;charset=utf-8")
public class UserController {

    @RequestMapping("/login")
    @ResponseBody
    public String login(String username, String pwd) throws JsonProcessingException {
        Map<String, Object> resultJson = new HashMap<>(4);
        Map<String, String> loginResult = new HashMap<>(4);
        loginResult.put("username", username);
        loginResult.put("pwd", pwd);
        loginResult.put("age", "20");
        loginResult.put("sex", "boy");

        resultJson.put("code", 200);
        resultJson.put("msg", "登录成功");
        resultJson.put("result", loginResult);

        return new ObjectMapper().writeValueAsString(resultJson);
    }

}
